Rails.application.routes.draw do

  # 定义用户资源路由
  get 'signup', to: 'users#new'
  post 'signup', to: 'users#create'
  # 定义用户资源路由, 只设置 show
  resources :users, only: [:show]

  # 定义会话资源路由
  get 'login', to: 'sessions#new'
  post 'login', to: 'sessions#create'
  get 'logout', to: 'sessions#destroy'

  # 定义关于页面路由
  get 'about', to: 'pages#about', as: :about_page

  # 定义联系页面路由
  get 'contact', to: 'pages#contact', as: :contact_page

  # 定义时间页面路由
  get 'time', to: 'pages#time', as: :time_page

  resources :microposts do
    # 集合路由
    collection do
      get :hot, as: :hot     # 热门微博
      get :recent, as: :recent  # 最新微博
      get :popular, as: :popular # 流行微博
    end

    # 成员路由
    member do
      get :like, as: :like # 点赞微博
    end
  end

  root 'microposts#index' # 设置根路径为微博列表

  # 处理URL附加参数
  # 路由参数
  get 'books/show2/:id', to: 'books#show2', as: :book_show2
  # 查询参数 ?title=xxx
  get 'books/search', to: 'books#search', as: :book_search

  # 定义books资源路由
  resources :books


  # 设置根路由为关于页面
  # root 'pages#about'

  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

  # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
  # Can be used by load balancers and uptime monitors to verify that the app is live.
  # get "up" => "rails/health#show", as: :rails_health_check

  # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
  # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
  # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker

  # Defines the root path route ("/")
  # root "posts#index"
end
